package com.labyrinth.core;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;

public class Trap extends GameObject
{
	public Trap()
	{
	}

	public Trap(float x, float y)
	{
		super(x, y);
		this.setScale(100, 100);
		setTexture("data/trap.png");
		this.setScale(100);
		setDrawType(GL10.GL_TRIANGLE_STRIP);
		setMesh();
	}

	public Trap(float x, float y, float height, float width)
	{
		super(x, y);
		this.setScale(width, height);
		setTexture("data/trap.png");
		setDrawType(GL10.GL_TRIANGLE_STRIP);
		setMesh();
	}

	public void setMesh()
	{
		mesh = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord"));
		mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 0, 1, 0.5f, -0.5f, 0, 1, 1, -0.5f, 0.5f, 0, 0, 0, 0.5f, 0.5f, 0, 1, 0 });
		mesh.setIndices(new short[] { 0, 1, 2, 3 });
		vertexCount = 4;

	}

	@Override
	public void draw()
	{
		Gdx.gl10.glPushMatrix();
		Gdx.gl10.glTranslatef(position.getX(), position.getY(), 0);
		Gdx.gl10.glScalef(scaleX, scaleY, 0);
		Gdx.graphics.getGL10().glEnable(GL10.GL_TEXTURE_2D);
		texture.bind();
		mesh.render(drawType, 0, vertexCount);
		Gdx.gl10.glPopMatrix();
	}

}
